package com.fansaikj.erp.domain.order;

/*
 * Copyright © 2020-2035 erupt.xyz All rights reserved.
 * Author: YuePeng (erupts@126.com)
 */

import javax.persistence.*;

import com.fansaikj.erp.domain.CapitalAccount;
import com.fansaikj.erp.domain.ExpenseApply;
import com.fansaikj.erp.domain.SettlementCompany;
import com.fansaikj.erp.domain.comtactCompany.CustomerCompany;
import lombok.Data;
import lombok.EqualsAndHashCode;
import xyz.erupt.annotation.*;
import xyz.erupt.annotation.sub_erupt.Filter;
import xyz.erupt.annotation.sub_field.*;
import xyz.erupt.annotation.sub_field.sub_edit.*;
import xyz.erupt.jpa.model.BaseModel;

import java.util.Set;
import java.util.Date;

@EqualsAndHashCode(callSuper = true)
@Erupt(name = "出库单")
@Table(name = "erp_sales_order")
@Entity
@Data
public class SalesOrder extends BaseModel {

    @EruptField(
            views = @View(
                    title = "主键ID", show = false
            ),
            edit = @Edit(
                    title = "主键ID",
                    type = EditType.INPUT, show = false, notNull = true,
                    inputType = @InputType
            )
    )
    private Long id;

    @EruptField(
            views = @View(
                    title = "销售单号"
            ),
            edit = @Edit(
                    title = "销售单号",
                    type = EditType.INPUT, search = @Search(vague = true), notNull = true,
                    inputType = @InputType
            )
    )
    private String orderNo;

    @EruptField(
            views = @View(
                    title = "销售日期"
            ),
            edit = @Edit(
                    title = "销售日期",
                    type = EditType.DATE, search = @Search(vague = true),
                    dateType = @DateType
            )
    )
    private Date salesDate;

    @EruptField(
            views = @View(
                    title = "往来客户",
                    column = "name"
            ),
            edit = @Edit(
                    title = "往来客户",
                    type = EditType.REFERENCE_TABLE, search = @Search, notNull = true,
                    referenceTableType = @ReferenceTableType(id = "id", label = "name")
            )
    )
    @ManyToOne
    private CustomerCompany customer;

    @EruptField(
            views = @View(
                    title = "结算单位",
                    column = "name"
            ),
            edit = @Edit(
                    title = "结算单位",
                    type = EditType.REFERENCE_TABLE, search = @Search, notNull = true,
                    referenceTableType = @ReferenceTableType(id = "id", label = "name")
            )
    )
    @ManyToOne
    private SettlementCompany settlementCompany;

    @EruptField(
            views = @View(
                    title = "收款账户",
                    column = "accountName"
            ),
            edit = @Edit(
                    title = "收款账户",
                    type = EditType.REFERENCE_TABLE,
                    referenceTableType = @ReferenceTableType(id = "id", label = "accountName")
            )
    )
    @ManyToOne
    private CapitalAccount reciveAccount;

    @EruptField(
            views = @View(
                    title = "结算方式"
            ),
            edit = @Edit(
                    title = "结算方式",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String settleType;

    @EruptField(
            views = @View(
                    title = "出库方式"
            ),
            edit = @Edit(
                    title = "出库方式",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String outStoreType;

    @EruptField(
            views = @View(
                    title = "发货方式"
            ),
            edit = @Edit(
                    title = "发货方式",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String pickupType;

    @EruptField(
            views = @View(
                    title = "送货地址"
            ),
            edit = @Edit(
                    title = "送货地址",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String pickupAddress;

    @EruptField(
            views = @View(
                    title = "计息类型"
            ),
            edit = @Edit(
                    title = "计息类型",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String interestType;

    @EruptField(
            views = @View(
                    title = "合同编号"
            ),
            edit = @Edit(
                    title = "合同编号",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String contractNo;

    @EruptField(
            views = @View(
                    title = "发票类型"
            ),
            edit = @Edit(
                    title = "发票类型",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String invoiceType;

    @EruptField(
            views = @View(
                    title = "清账月份"
            ),
            edit = @Edit(
                    title = "清账月份",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String clearingMonth;

    @EruptField(
            views = @View(
                    title = "销售金额"
            ),
            edit = @Edit(
                    title = "销售金额",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String salesAmount;

    @EruptField(
            views = @View(
                    title = "核销状态"
            ),
            edit = @Edit(
                    title = "核销状态",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String writeOffStatus;

    @EruptField(
            views = @View(
                    title = "核销金额"
            ),
            edit = @Edit(
                    title = "核销金额",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String writeOffAmount;

    @EruptField(
            views = @View(
                    title = "初审人"
            ),
            edit = @Edit(
                    title = "初审人",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String firstChecker;

    @EruptField(
            views = @View(
                    title = "初审时间"
            ),
            edit = @Edit(
                    title = "初审时间",
                    type = EditType.DATE,
                    dateType = @DateType
            )
    )
    private Date firstCheckTime;

    @EruptField(
            views = @View(
                    title = "审核人"
            ),
            edit = @Edit(
                    title = "审核人",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String secondChecker;

    @EruptField(
            views = @View(
                    title = "审核时间"
            ),
            edit = @Edit(
                    title = "审核时间",
                    type = EditType.DATE,
                    dateType = @DateType
            )
    )
    private Date secondCheckTime;

    @EruptField(
            views = @View(
                    title = "创建人", show = false
            ),
            edit = @Edit(
                    title = "创建人",
                    type = EditType.INPUT, show = false,
                    inputType = @InputType
            )
    )
    private String createBy;

    @EruptField(
            views = @View(
                    title = "创建时间", show = false
            ),
            edit = @Edit(
                    title = "创建时间",
                    type = EditType.DATE, show = false,
                    dateType = @DateType
            )
    )
    private Date createTime;

    @EruptField(
            views = @View(
                    title = "修改人", show = false
            ),
            edit = @Edit(
                    title = "修改人",
                    type = EditType.INPUT, show = false,
                    inputType = @InputType
            )
    )
    private String updateBy;

    @EruptField(
            views = @View(
                    title = "修改时间", show = false
            ),
            edit = @Edit(
                    title = "修改时间",
                    type = EditType.DATE, show = false,
                    dateType = @DateType
            )
    )
    private Date updateTime;

    @EruptField(
            views = @View(
                    title = "备注"
            ),
            edit = @Edit(
                    title = "备注",
                    type = EditType.TEXTAREA
            )
    )
    private String remark;

    @EruptField(
            views = @View(
                    title = "所属部门"
            ),
            edit = @Edit(
                    title = "所属部门",
                    type = EditType.INPUT,
                    inputType = @InputType
            )
    )
    private String sysOrgCode;

    @EruptField(
            views = @View(
                    title = "采购订单状态"
            ),
            edit = @Edit(
                    title = "采购订单状态",
                    type = EditType.CHOICE,
                    choiceType = @ChoiceType(
                            vl = {
                                    @VL(value = "xxx", label = "xxx"),
                                    @VL(value = "yyy", label = "yyy")
                            }
                    )
            )
    )
    private String orderStatus;

    @EruptField(
            views = @View(
                    title = "是否已提交"
            ),
            edit = @Edit(
                    title = "是否已提交",
                    type = EditType.BOOLEAN,
                    boolType = @BoolType
            )
    )
    private Boolean isSubmit;

    @EruptField(
            views = @View(
                    title = "删除状态(0-正常,1-已删除)", show = false
            ),
            edit = @Edit(
                    title = "删除状态(0-正常,1-已删除)",
                    type = EditType.INPUT, show = false,
                    inputType = @InputType
            )
    )
    private String delFlag;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinColumn(name = "salesOrderId")
    @EruptField(
            edit = @Edit(
                    title = "出库单明细",
                    type = EditType.TAB_TABLE_ADD
            )
    )
    private Set<SalesOrderDetail> salesOrderDetails;

    @OneToMany(fetch = FetchType.LAZY)
    @JoinTable(
            joinColumns = @JoinColumn(name = "salesOrderId", referencedColumnName = "id")
    )
    @EruptField(
            edit = @Edit(
                    title = "关联费用单",
                    type = EditType.TAB_TABLE_REFER,
                    filter = @Filter(

                    )
            )
    )
    private Set<ExpenseApply> expenseApplies;
}